#include <wx/wxprec.h>
#include <wx/wx.h>
#include <wx/dialog.h>
#include <wx/combobox.h>
#include <wx/sizer.h>
#include <wx/panel.h>
#include <wx/filepicker.h>
#include <wx/checklst.h>
#include <wx/textctrl.h>
#include <wx/button.h>

#include <string>

#include "ImportDlg.h"

enum
{
	ID_COMBO = wxID_HIGHEST + 1,
	ID_FILEPICER,
};

BEGIN_EVENT_TABLE(CImportDlg, wxDialog)
	EVT_COMBOBOX(ID_COMBO, CImportDlg::OnTypeSel)
	EVT_FILEPICKER_CHANGED(ID_FILEPICER, CImportDlg::OnFilePicker)
END_EVENT_TABLE()


CImportDlg::CImportDlg(wxWindow* parent, wxWindowID id, wxString title) : wxDialog(parent, id, title)
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );

	wxBoxSizer* m_mainSizer;
	m_mainSizer = new wxBoxSizer( wxVERTICAL );

	m_panel1 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxBoxSizer* bSizer1;
	bSizer1 = new wxBoxSizer( wxHORIZONTAL );

	m_staticTextType = new wxStaticText( m_panel1, wxID_ANY, wxT("Type"), wxDefaultPosition, wxSize( 50,-1 ), 0 );
	m_staticTextType->Wrap( -1 );
	m_staticTextType->SetMinSize( wxSize( 50,-1 ) );

	bSizer1->Add( m_staticTextType, 0, wxALL, 5 );

	m_cbType = new wxComboBox( m_panel1, ID_COMBO, wxT("Combo!"), wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); 
	bSizer1->Add( m_cbType, 1, wxALL, 5 );
	m_cbType->AppendString(_("SG_TypeA"));
	m_cbType->AppendString(_("SG_TypeB"));

	m_panel1->SetSizer( bSizer1 );
	m_panel1->Layout();
	bSizer1->Fit( m_panel1 );
	m_mainSizer->Add( m_panel1, 0, wxEXPAND | wxALL, 5 );

	m_panel2 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxBoxSizer* bSizer2;
	bSizer2 = new wxBoxSizer( wxHORIZONTAL );

	m_staticTextPath = new wxStaticText( m_panel2, wxID_ANY, wxT("ExcelFile"), wxDefaultPosition, wxSize( 50,-1 ), 0 );
	m_staticTextPath->Wrap( -1 );
	m_staticTextPath->SetMinSize( wxSize( 50,-1 ) );

	bSizer2->Add( m_staticTextPath, 0, wxALL, 5 );

	m_pFilePicker = new wxFilePickerCtrl( m_panel2, ID_FILEPICER, wxEmptyString, wxT("Select a Excel File"), "excel files (*.xlsx) | *.xlsx", wxDefaultPosition, wxDefaultSize );
	bSizer2->Add( m_pFilePicker, 1, wxALL, 5 );

	m_panel2->SetSizer( bSizer2 );
	m_panel2->Layout();
	bSizer2->Fit( m_panel2 );
	m_mainSizer->Add( m_panel2, 0, wxEXPAND | wxALL, 5 );

	m_panel3 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxBoxSizer* bSizer3;
	bSizer3 = new wxBoxSizer( wxHORIZONTAL );

	m_staticTextSheet = new wxStaticText( m_panel3, wxID_ANY, wxT("Sheet"), wxDefaultPosition, wxSize( 50,-1 ), 0 );
	m_staticTextSheet->Wrap( -1 );
	m_staticTextSheet->SetMinSize( wxSize( 50,-1 ) );

	bSizer3->Add( m_staticTextSheet, 0, wxALL, 5 );

	wxArrayString m_checkListChoices;
	m_checkList = new wxCheckListBox( m_panel3, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_checkListChoices, 0 );
	bSizer3->Add( m_checkList, 1, wxALL, 5 );
	
	for(unsigned int i = 0; i < 3; ++i)
	{
		char szInfo[10];
		sprintf(szInfo, "Sheet:%d", i);
		wxString strValue = szInfo;
		m_checkList->InsertItems(1, &strValue, i);
	}

	m_panel3->SetSizer( bSizer3 );
	m_panel3->Layout();
	bSizer3->Fit( m_panel3 );
	m_mainSizer->Add( m_panel3, 0, wxEXPAND | wxALL, 5 );

	m_panel4 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxBoxSizer* bSizer4;
	bSizer4 = new wxBoxSizer( wxHORIZONTAL );

	m_staticTextKey = new wxStaticText( m_panel4, wxID_ANY, wxT("Key"), wxDefaultPosition, wxSize( 50,-1 ), 0 );
	m_staticTextKey->Wrap( -1 );
	m_staticTextKey->SetMinSize( wxSize( 50,-1 ) );

	bSizer4->Add( m_staticTextKey, 0, wxALL, 5 );

	m_textCtrlKey = new wxTextCtrl( m_panel4, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	bSizer4->Add( m_textCtrlKey, 1, wxALL, 5 );

	m_btnOK = new wxButton( m_panel4, wxID_OK, wxT("Ok"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer4->Add( m_btnOK, 0, wxALL, 5 );

	m_panel4->SetSizer( bSizer4 );
	m_panel4->Layout();
	bSizer4->Fit( m_panel4 );
	m_mainSizer->Add( m_panel4, 0, wxEXPAND | wxALL, 5 );

	this->SetSizer( m_mainSizer );
	this->Layout();
}

CImportDlg::~CImportDlg()
{
}

void CImportDlg::OnFilePicker(wxFileDirPickerEvent& event)
{
	wxLogDebug(_("OnFilePicker"));
	wxLogDebug(GetPath());
}

void CImportDlg::OnTypeSel(wxCommandEvent& event)
{
	wxLogDebug(_("OnTypeSel"));
	m_textCtrlKey->SetValue(m_cbType->GetStringSelection());
}

wxString CImportDlg::GetPath()
{
	return m_pFilePicker->GetPath();
}
